/**
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 */
package com.jeesite.modules.goods.web;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSONObject;
import com.jeesite.common.config.Global;
import com.jeesite.common.entity.Page;
import com.jeesite.common.lang.DateUtils;
import com.jeesite.common.responseReturn.utils.CommonUtils;
import com.jeesite.common.utils.KdniaoTrackQueryAPI;
import com.jeesite.common.web.BaseController;
import com.jeesite.modules.config.MyProps;
import com.jeesite.modules.goods.entity.ZtColor;
import com.jeesite.modules.goods.entity.ZtGoods;
import com.jeesite.modules.goods.entity.ZtOrder;
import com.jeesite.modules.goods.entity.ZtQuan;
import com.jeesite.modules.goods.entity.ZtQuanself;
import com.jeesite.modules.goods.entity.ZtWl;
import com.jeesite.modules.goods.service.ZtColorService;
import com.jeesite.modules.goods.service.ZtGoodsService;
import com.jeesite.modules.goods.service.ZtOrderService;
import com.jeesite.modules.goods.service.ZtQuanselfService;
import com.jeesite.modules.recovery.entity.ZtWL;
import com.jeesite.modules.sys.service.DictDataService;
import com.jeesite.modules.sys.service.UserService;
import com.jeesite.modules.sys.utils.DictUtils;

/**
 * 测试数据Controller
 * 
 * @author ThinkGem
 * @version 2018-04-22
 */
@Controller
@RequestMapping(value = "${adminPath}/ztXJOrder")
public class ZtXJOrderController extends BaseController {

	@Autowired
	private ZtOrderService ztOrderService;

	@Autowired
	private UserService userService;

	@Autowired
	private ZtGoodsService ztGoodsService;
	@Autowired
	private ZtColorService ztColorService;

	@Autowired
	private ZtQuanselfService ztQuanselfService;

	@Autowired
	private MyProps myProps;

	/**
	 * 获取数据
	 */
	@ModelAttribute
	public ZtOrder get(String id, boolean isNewRecord) {
		ZtOrder ztOrder = new ZtOrder();
		if (StringUtils.isNotBlank(id)) {
			ztOrder.setId(id);
			ztOrder = ztOrderService.get(ztOrder);
		}
		if (ztOrder == null) {
			ztOrder = new ZtOrder();
		}
		return ztOrder;
	}

	/**
	 * 查询列表
	 */
	@RequiresPermissions("ztXJOrder:ztXJOrderData:view")
	@RequestMapping(value = { "list", "" })
	public String list(ZtOrder ztOrder, Model model) {
		model.addAttribute("ztOrder", ztOrder);

		return "modules/ztXJOrder/ztOrderList";
	}

	
	DictDataService dictDataService;

	/**
	 * 保存数据
	 */
	@RequiresPermissions("ztXJOrder:ztXJOrderData:edit")
	@PostMapping(value = "save")
	@ResponseBody
	public String save(@Validated ZtOrder ztOrder) {
		
		if(StringUtils.isNotBlank(ztOrder.getLogisticsCode())){
			ztOrder.setLogisticsName(ZtWL.getKey(ztOrder.getLogisticsCode()));
		}

		ztOrderService.save(ztOrder);

		return renderResult(Global.TRUE, text("保存订单成功！"));
	}

	/*
	 * @RequiresPermissions("ztOrder:ztOrderData:edit")
	 * 
	 * @RequestMapping(value = "enable")
	 * 
	 * @ResponseBody public String enable(ZtOrder ztOrder) {
	 * ztOrder.setUsestatus("0"); ztOrderService.updateUsestatus(ztOrder);
	 * return renderResult(Global.TRUE, text("券变更为有效成功")); }
	 */

	/**
	 * 删除数据
	 */
	@RequiresPermissions("ztXJOrder:ztXJOrderData:edit")
	@RequestMapping(value = "delete")
	@ResponseBody
	public String delete(ZtOrder ztOrder) {
		ztOrderService.delete(ztOrder);
		return renderResult(Global.TRUE, text("删除订单成功！"));
	}
}